package org.xdq.yzmdemo;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet( "/login")
public class LoginServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userid = request.getParameter("userid");
        String pwd = request.getParameter("pwd");
        String code = request.getParameter("code");
        String key = request.getParameter("key");

        if(!YzmCache.verfyCode(key,code)){
            response.getWriter().print("1");
        }else if("test".equals(userid) && "test".equals(pwd)){
            response.getWriter().print("0");
        }else{
            response.getWriter().print("2");
        }

        response.getWriter().flush();
        response.getWriter().close();

    }
}
